using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Publicuse.Application;
using Publicuse.Application.system;
using Publicuse.Autofac;
using Publicuse.Entity;
using Publicuse.Interface;
using Publicuse.Interface.Extend;
using Geekeradmin.Authorize;

namespace Geekeradmin.Controllers.system
{
    /// <summary>
    /// 系统生成下载任务信息
    /// </summary>
    [UserAuthorize("Admin"), AllowAnonymous]
    public class DowntaskController : BaseController
    {
        public DowntaskController(IAutofaceInstance autoface, IMySqlSugarService mySqlSugar, IWebHostEnvironment webHost, 
            IOptions<DBConnectionOption> options, IBaseServiceExt baseServiceExt)
            : base(autoface, mySqlSugar, webHost, options, baseServiceExt)
        {
        }

        /// <summary>
        /// 获取部门信息列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost("GetList")]
        public async Task<JsonResult> GetList(Downtask query)
        {
            CommonResult result = await DowntaskApplication.GetApplication(this.container).GetList(query);
            return new JsonResult(result);
        }

        /// <summary>
        /// 删除系统生成下载任务信息
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="loginUserCode"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        [HttpGet("Delete")]
        public async Task<JsonResult> Delete(string Id, string loginUserCode, string type = "-9")
        {
            CommonResult result = await DowntaskApplication.GetApplication(this.container).Delete(Id, loginUserCode, type);
            return new JsonResult(result);
        }

        /// <summary>
        /// 还原系统生成下载任务信息
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="loginUserCode"></param>
        /// <returns></returns>
        [HttpGet("Reduction"), AllowAnonymous]
        public async Task<JsonResult> Reduction(string Id, string loginUserCode)
        {
            CommonResult result = await DowntaskApplication.GetApplication(this.container).Reduction(Id, loginUserCode);
            return new JsonResult(result);
        }
    }
}
